package com.baosight.sczx.common.zm.cInterface.cb;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiColumn;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.spring.SpringApplicationContext;
import com.baosight.iplat4j.dao.Dao;

/**
 * 煤层 对外接口
 * <p>Title: Mine.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 高强
 * @version 1.0
 * <pre>Histroy:
 *          2013-7-3 上午11:01:49  高强  Create
 *</pre>
 */
public class Coalseam {

	private static Dao dao = (Dao)SpringApplicationContext.getBean("dao");
	
	/**
	 * 矿井建模 中用到的煤层
	 * <p>Function: getLevel</p>
	 * <p>Description: </p>
	 * <p>return value:List<Map></p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *   2013-7-3 上午11:01:49  高强 
	 * </p>
	 *
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static List<Map> getCoalseam(Map<String, String> _argMap){
		_argMap = _argMap == null ? new HashMap<String, String>():_argMap;
		List<Map>  _list = new ArrayList();
		try {
			_list = dao.query("ZMCBCoalseam.queryTree", _argMap);
		} catch (Exception e) {
			
		}
		return _list;
	}
	
	/**
	 * <p>Function: getParnetInforWfBlock</p>
	 * <p>Description: </p>
	 * <p>return value: EiBlock</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 * 2013-7-3 上午11:01:49  高强 
	 * </p>
	 *
	*/
	@SuppressWarnings({ "rawtypes", "unchecked"})
	public static EiBlock getParnetInforCBlock()
	{
		EiBlock block = new EiBlock("cmes.cb.parentInforC");

		EiColumn eiColumn = new EiColumn("display");
		eiColumn.setType("C");
		block.addMeta(eiColumn);

		eiColumn = new EiColumn("value");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		eiColumn = new EiColumn("fdDensity");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		List<Map>  _list = new ArrayList<Map>();
	   _list = dao.query("ZMCBCoalseam.queryInterface", null);
		block.setRows(_list);
		return block;
	}
	
	/**构造是或者否block
	 * <p>Function: getYesORNoBlock</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCB01</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2013-7-3 上午11:01:49  高强 
	 * </p>
	 *
	*/
	@SuppressWarnings("rawtypes")
	public static EiBlock  getWorkStatusBlock(String blockName)
	{
		EiBlock block = new EiBlock(blockName);

		EiColumn eiColumn = new EiColumn("value");
		eiColumn.setType("C");
		block.addMeta(eiColumn);

		eiColumn = new EiColumn("display");
		eiColumn.setType("C");
		block.addMeta(eiColumn);
		
		List<Map>  _list = new ArrayList<Map>();
		Map<String, String> _map = new HashMap<String, String>();
		
		_map = new HashMap<String, String>();
		_map.put("display", "设计");
		_map.put("value", "设计");
        _list.add(_map);
        
        _map = new HashMap<String, String>();
		_map.put("display", "开工");
		_map.put("value", "开工");
        _list.add(_map);
        
        _map = new HashMap<String, String>();
		_map.put("display", "完工");
		_map.put("value", "完工");
        _list.add(_map);
        block.setRows(_list);
		return block;
	}
	
	/**
	 * 验证 煤层是否被工作面使用
	 * <p>Function: validateUsed</p>
	 * <p>Description: </p>
	 * <p>return value:boolean</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2013-7-11下午16:27:19 王开兵
	 * </p>
	 *
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static boolean validateUsed(Map<String,List<String>> _argMap, EiInfo eiInfo) {
		_argMap = _argMap == null ? new HashMap<String, List<String>>():_argMap;
		
		List<Map>  _list = new ArrayList();

		try {
			_list = dao.query("ZMCBWorkingface.isDeleteCoalseam", _argMap);
			if(_list.size() < 1) {
				return false;
			}
			else {
				eiInfo.setStatus(-1);
				eiInfo.setMsg("该煤层已被使用，不能删除！");
			}
		} catch (Exception e) {
			System.out.println("验证煤层是否被使用异常: " + e.getMessage());
		}

		return true;
	}
}
